package com.tanhua.server.service;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.tanhua.common.pojo.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.io.IOException;

@Service
@Slf4j
public class UserService {
    @Autowired
    private RestTemplate restTemplate;
    @Value("${tanhua.sso.url}")
    private String ssoUrl;

    /**
     * 提供功能:根据rest接口远程调用token校验的服务
     *
     * @param token
     * @return
     */
    public User getTokenCheck(String token) {
        try {
            String url = ssoUrl + "/user/" + token;
            String object = restTemplate.getForObject(url, String.class);
            User user = new ObjectMapper().readValue(object, User.class);
            return user;
        } catch (IOException e) {
            log.error("远程调用token服务失败!userService的34行!");
            return null;
        }
    }

}
